14. Markdown Cells
Markdown Cells
As mentioned before, cells can also be used for text written in Markdown. Markdown is a formatting syntax that allows you to include links, style text as bold or italicized, and format code. As with code cells, you press Shift + Enter or Control + Enter to run the Markdown cell, where it will render the Markdown to formatted text. Including text allows you to write a narrative alongside your code, as well as documenting your code and the thoughts that went into it.
Below is a brief summary of markup concepts. At the bottom of this page, you'll find very good resources to learn and practice markup concepts:
Headers
You can write headers using the pound/hash/octothorpe symbol #
placed before the text. One #
renders as an h1
header, two #
s is an h2, and so on. Looks like this:
# Header 1
## Header 2
### Header 3
renders as
Header 1
Header 2
Header 3
Links
Linking in Markdown is done by enclosing text in square brackets and the URL in parentheses, like this [Udacity's home page](https://www.udacity.com)
for a link to Udacity's home page.
Emphasis
You can add emphasis through bold or italics with asterisks or underscores (*
or _
). For italics, wrap the text in one asterisk or underscore, _gelato_
or *gelato*
renders as gelato.
Bold text uses two symbols, **aardvark**
or __aardvark__
looks like aardvark.
Either asterisks or underscores are fine as long as you use the same symbol on both sides of the text.
Code
There are two different ways to display code, inline with text and as a code block separated from the text. To format inline code, wrap the text in backticks. For example, `string.punctuation`
renders as string.punctuation
.
To create a code block, start a new line and wrap the text in three backticks
```
import requests
response = requests.get('https://www.udacity.com')
```
or indent each line of the code block with four spaces.
import requests
response = requests.get('https://www.udacity.com')
Note: You won't see the spaces here in the page for the above! Udacity's classroom is rendering the spaces directly as a code block.
Math expressions
You can create math expressions in Markdown cells using LaTeX symbols. Notebooks use MathJax to render the LaTeX symbols as math symbols. To start math mode, wrap the LaTeX in dollar signs $y = mx + b$
for inline math. For a math block, use double dollar signs,
$$
y = \frac{a}{b+c}
$$
This is a really useful feature, so if you don't have experience with LaTeX, here is a tutorial on using it to create math expressions.
Markdown Tutorial and Cheatsheet
To get a better hands-on practice with markdown text, we recommend you to try this interactive tutorial on basic markdown concepts. Also, you can bookmark either of the following two cheatsheets:
We recommend making use of the Markdown cells. Your notebooks will be much more readable compared to a bunch of code blocks.